/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package topcoder;

import java.util.Arrays;

/**
 *
 * @author Mohamed.Azouz
 */
public class SantaGifts {

    public String[] distribute(String[] gifts, int n) {
        String tot[] = new String[n];
        int totNum[] = new int[n];
        Arrays.fill(tot, "");
        for (int i = 0; i < gifts.length; i++) {
            if (totNum[i % n] < 3) {
                if (!tot[i % n].equals("")) {
                    tot[i % n] += " ";
                    totNum[i % n]++;
                }
                tot[i % n] += gifts[i];
            }
        }
        return tot;
    }

    public static void main(String[] args) {
        SantaGifts gifts = new SantaGifts();
        String ar[] = {"ball", "plane", "robot", "puzzle", "bike"};
        int n = 1;
        System.out.println(Arrays.toString(gifts.distribute(ar, n)));
    }
}
